﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace DienThoai
{
    /// <summary>
    /// Interaction logic for BuyingQuantity.xaml
    /// </summary>
    public partial class BuyingQuantity : Window
    {
        public int Quantity;
        int Max;
        public BuyingQuantity(string Max)
        {
            InitializeComponent();
            this.Quantity =0;
            this.Max = int.Parse(Max);
           // txtQuantity.Text = Max;
        }

        private void btOk_Click(object sender, RoutedEventArgs e)
        {
            Quantity = int.Parse(txtQuantity.Text);
            
            DialogResult = true;
        }

        private void btCancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }


        private void txtQuantity_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key >= Key.D0 && e.Key <= Key.D9)
            {
                if(txtQuantity.Text !="")
                    if (int.Parse(txtQuantity.Text) >= Max)
                    {
                        e.Handled = true;                    
                        txtQuantity.Text = Max.ToString();
                
                    }
                    else
                        e.Handled = false;
            }
            else
                e.Handled = true;
            
         }

        private void txtQuantity_TextChanged(object sender, TextChangedEventArgs e)
        {
            if(txtQuantity.Text !="")
                if (int.Parse(txtQuantity.Text) >= Max)
                {
                    txtQuantity.Text = Max.ToString();

                }
        }


    }
}
